package com.fyzk.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.fyzk.bean.RechargeBean;
import com.tyjc.lottery.R;

import http.DataUtil.text.TextUtil;

/**
 * <p>
 *
 * @author 指尖沙漏
 * @mood
 * @description
 * @date 2019/6/10 17:13
 * </p>
 */
public class OfflineDialog extends Dialog implements View.OnClickListener {
    private Context mContext;
    private TextView mTvTitle;
    private TextView mobileTxt;
    private TextView wxTxt;
    private ImageView ivCode;
    private TextView submitTxt;
    private RechargeBean rechargeBean;
    private String titleText = "";

    public OfflineDialog(Context context, RechargeBean rechargeBean) {
        this(context,rechargeBean,"线下支付");
    }

    public OfflineDialog(Context context, RechargeBean rechargeBean,String title) {
        super(context, R.style.commonDialog);
        this.mContext = context;
        this.rechargeBean = rechargeBean;
        this.titleText = title;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_off_line);
        setCanceledOnTouchOutside(false);
        initView();
    }

    private void initView() {
        mTvTitle = findViewById(R.id.tv_title);
        mobileTxt = findViewById(R.id.mobile);
        wxTxt = findViewById(R.id.wx);
        ivCode = findViewById(R.id.code);
        submitTxt = findViewById(R.id.submit);
        submitTxt.setOnClickListener(this);

        mTvTitle.setText(titleText);
        if (TextUtil.isEmpty(titleText)){
            mTvTitle.setVisibility(View.GONE);
            setViewGravity(mobileTxt);
            setViewGravity(wxTxt);
        }

        if (rechargeBean != null) {
            mobileTxt.setText("客服电话：" + rechargeBean.getPhone());
            wxTxt.setText("微信号：" + rechargeBean.getWx());

            Glide.with(mContext).load(rechargeBean.getImage())
                    .error(R.mipmap.ic_launcher)
                    .into(ivCode);
        }
    }

    private void setViewGravity(View view) {
        ViewGroup.LayoutParams params = view.getLayoutParams();
        if (params instanceof LinearLayout.LayoutParams){
            ((LinearLayout.LayoutParams) params).gravity = Gravity.CENTER_HORIZONTAL;
            view.setLayoutParams(params);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.submit:
                dismiss();
                break;
        }
    }

}
